import { logout, login } from '@/api/person'
// import { submitRes } from '@/api/index'
const user = {
  state: {
    token: '',
  },
  mutations: {
    SET_TOKEN: (state, token) => {
      state.token = token
    },
  },

  actions: {
    // 登录
    // login({ commit }, userInfo) {
    //   return new Promise((resolve, reject) => {
    //     login(userInfo)
    //       .then((response) => {
    //         if (response.code == 0) {
    //           const res = response.data
    //           localStorage.setItem('Access-Token', res.xAuthToken)
    //           commit('SET_TOKEN', res.xAuthToken)
    //           localStorage.setItem('userName', res.userName)
    //           localStorage.setItem('sceneList', res.sceneList)
    //           this.queryParams = res.areaLevel
    //           localStorage.setItem(
    //             'areaLevel',
    //             JSON.stringify(this.queryParams),
    //           )
    //           resolve(response)
    //         } else {
    //           resolve(response)
    //         }
    //       })
    //       .catch((error) => {
    //         reject(error)
    //       })
    //   })
    // },
    // 登出
    Logout({ commit }) {
      return new Promise((resolve) => {
        logout()
          .then(() => {
            commit('SET_TOKEN', '')
            localStorage.removeItem('client_authorization')
            localStorage.removeItem('userName')
            localStorage.removeItem('sceneList')
            localStorage.removeItem('areaLevel')
            localStorage.removeItem('roleName')
            localStorage.removeItem('roleDate')
            resolve()
          })
          .catch(() => {
            resolve()
          })
          .finally(() => {})
      })
    },
  },
}

export default user
